<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8" isELIgnored="false"%>

<%
	request.setAttribute("title","保险信息");
	request.setAttribute("modelConfigPath", "insu");
%>

<%@ include file="/WEB-INF/views/shared/master/contentHeader.jsp"%>
<style type="text/css">
.content{
	margin-buttom:28px;
}
</style>

<t:panel cssClass="panel-flat form-detailed" customBody="true" customHead="true">
    <div class="detailed-navbar-content panel-body">
        <t:form commandName="insurance" action="/admin/insu/insurance/save" method="post" cssClass="form-horizontal">
            <div class="hide">
                <t:hidden path="id"/>
                <t:hidden path="deleteMark"/>
                <t:input type="hidden" path="mainImg" />
                <t:input type="hidden" path="addImg" />
                <input type="hidden" id="insurancePeopleIds" value="${insurancePeopleIds}" />  
            </div>
            <t:formgroup>
                <t:label path="insuranceName" cssClass="col-sm-2" />
                <t:input path="insuranceName" colClass="col-sm-10" />
            </t:formgroup>
             <t:formgroup>
                <t:label path="peopleId" cssClass="col-sm-2" />
                <t:select2 path="peopleId" colClass="col-sm-10" multiple="true" />
            </t:formgroup>
            <t:formgroup>
                <t:label path="minPremium" cssClass="col-sm-2" />
                <t:input path="minPremium" colClass="col-sm-4"/>
                <t:label path="totalProportion" cssClass="col-sm-2" /> 
                <t:input path="totalProportion" colClass="col-sm-4" />
            </t:formgroup>
            <t:formgroup>
                <t:label path="insuranceOne" cssClass="col-sm-2" />
                <t:select2 path="insuranceOne" colClass="col-sm-4" />
                <t:select2 path="insuranceTwo" colClass="col-sm-4" />
            </t:formgroup>
            <t:formgroup>
                <t:label path="status" cssClass="col-sm-2" />
                <t:select2 path="status" colClass="col-sm-4" />
                <t:label path="state" cssClass="col-sm-2" /> 
                <t:selectButton path="state" colClass="col-sm-4" />
            </t:formgroup>
             <t:formgroup>
                <t:label path="channelName" cssClass="col-sm-2" />
                <t:select2 path="channelName" colClass="col-sm-4" />
            </t:formgroup>
            <t:formgroup>
                <t:label path="insuranceCompanyId" cssClass="col-sm-2" />
                <t:select2 path="insuranceCompanyId" colClass="col-sm-4" />
                <t:label path="hesitatePeriod" cssClass="col-sm-2" /> 
                <t:input path="hesitatePeriod" colClass="col-sm-4" />
            </t:formgroup>
            <t:formgroup>
                <t:label path="insuranceLink" cssClass="col-sm-2" /> 
                <t:input path="insuranceLink" colClass="col-sm-4" />
                <t:label path="insuSortCode" cssClass="col-sm-2" />
                <t:input path="insuSortCode" colClass="col-sm-4" />
            </t:formgroup>
            <t:formgroup>
                <t:label path="securityPlan" cssClass="col-sm-2" />
                <t:input path="securityPlan" colClass="col-sm-4" />
                <t:label id="hotInsu" path="hotSortCode" cssClass="col-sm-2" />
                <t:input path="hotSortCode" colClass="col-sm-4" />
            </t:formgroup>
            <t:formgroup>
                <t:label path="shareProportionOne" cssClass="col-sm-2" />
                <t:input path="shareProportionOne" colClass="col-sm-4" readonly="true"/>
                <t:label path="shareProportionTwo" cssClass="col-sm-2" />
                <t:input path="shareProportionTwo" colClass="col-sm-4" readonly="true"/>
            </t:formgroup>
              <t:formgroup>
                <t:label path="spreadProportion" cssClass="col-sm-2"  />
                <t:input path="spreadProportion" colClass="col-sm-4" readonly="true" />
                <t:label path="hatchProportion" cssClass="col-sm-2" />
                <t:input path="hatchProportion" colClass="col-sm-4" readonly="true"/>
            </t:formgroup>
             <t:formgroup>
                <t:label path="serverProportion" cssClass="col-sm-2" />
                <t:input path="serverProportion" colClass="col-sm-4" readonly="true" />
                <t:label path="cityProportion" cssClass="col-sm-2" />
                <t:input path="cityProportion" colClass="col-sm-4" readonly="true" />
            </t:formgroup>
            <!--  <t:formgroup>
                <t:label path="manageProportion" cssClass="col-sm-2" />
                <t:input path="manageProportion" colClass="col-sm-4" readonly="true" disabled="true" /> 
                <t:label path="companyProportion" cssClass="col-sm-2" />
                <t:input path="companyProportion" colClass="col-sm-4" readonly="true" />
             </t:formgroup> -->
            <t:formgroup>
                <div class="col-sm-6">
                 <t:label path="mainImg" cssClass="col-sm-4" />
                    <div class="col-sm-4">
                    <c:if test="${insurance.mainImg!=null && insurance.mainImg!=''}">
					    <img style="width:100px; height:80px;" id="mainPicShow" src="${tfn:getFileUrl(insurance.mainImg)}" /> 
				    </c:if>
				    <c:if test="${insurance.mainImg ==null || insurance.mainImg==''}">
						 <img style="width:100px; height:80px;" id="mainPicShow" src="<c:url value='/images/we/invitationIndex/bg1.jpg' />" />
				    </c:if>
				    </div>
				    <div class="col-sm-4">
				    <label>加载进度</label>
                      <div style="width:100px;height: 10px;margin-top:0.5rem; border: 2px solid #afafaf;border-radius:15px;"class="mainParent">
        			    <div style="width:0px;height: 7px;background-color: #afafaf" class="mainProgress"></div>
        		      </div> 
        		      <button type="button" class="btn-info" id="deleteAddPic" style="padding-left:10px; border-radius:6px; margin-top:1rem">删除图片</button>
        		    </div>
                </div>
                <div class="col-sm-6">
                <t:label path="addImg" cssClass="col-sm-4" />
                  <div class="col-sm-4">
                    <c:if test="${insurance.addImg!=null && insurance.addImg!=''}">
					    <img style="width:100px; height:80px;" id="addPicShow" src="${tfn:getFileUrl(insurance.addImg)}" /> 
				    </c:if>
				    <c:if test="${insurance.addImg ==null || insurance.addImg==''}">
						 <img style="width:100px; height:80px;" id="addPicShow" src="<c:url value='/images/we/invitationIndex/bg1.jpg' />" />
				    </c:if>
				  </div>
				  <div class="col-sm-4"> 
				      <label>加载进度</label>
                      <div style="width:100px;height: 10px;margin-top:0.5rem; border: 2px solid #afafaf;border-radius:15px;"class="addParent">
        			    <div style="width:0px;height: 7px;background-color: #afafaf" class="addProgress"></div>
        		      </div>
					<button type="button" class="btn-info" id="deleteAddPic" style="padding-left:10px; border-radius:6px; margin-top:1rem">删除图片</button>
        		      </div>
                  </div>
            </t:formgroup>   
            <t:formgroup>
                <t:label path="insuranceContent" cssClass="col-sm-2" />
                <t:ueditor path="insuranceContent" style="height:150px" colClass="col-sm-10" />
            </t:formgroup>
        </t:form>
    </div>
    <div class="navbar-fixed-bottom">
	<t:panelFoot headingBtnCssClass="heading-btn pull-right-important">
		<t:button icon="icon-floppy-disk" onclick="saveData()" cssClass="btn-info" csize="sm">保存</t:button>
	</t:panelFoot>
	</div>
</t:panel>

<script type="text/javascript">
	function saveData(){
		if (!$("form:first").valid()){
			return;
		}
		
		if($(".select2-selection__rendered li").length<2){
			$("#peopleId option").attr("selected","selected");
		}
		$("form:first").submit(); 

	}	
	/* -------------------------保险产品的二级级联--------------------------- */
	$(function() {
		var options = {}
		options.links = [];
		options.links.push({
			id : 'insuranceOne',
			selector : '#insuranceOne',
			paramName : 'insuranceOne',
			depend : 'first'
		});
		options.links.push({
			id : 'insuranceTwo',
			selector : '#insuranceTwo',
			paramName : 'insuranceTwo',
			depend : 'insuranceOne'
		});

		$.linker(options);
	})
	
	/* -------------------------进度条--------------------------- */
	$(function(){
		$("#mainPicShow").on('click',function(e) {
			$(".mainProgress").width(0);
			$("#mainImg").startCosFileUpload({
				fillImg:"#mainPicShow",
				progressCallback:function(curr, sha1){
					$(".mainParent").show();
					$(".mainProgress").width(0);
					$(".mainProgress").width(sha1*96);
				}
			});
		});
		$("#addPicShow").on('click',function(e) {
			$(".addProgress").width(0);
			$("#addImg").startCosFileUpload({
				fillImg:"#addPicShow",
					progressCallback:function(curr, sha1){
						$(".addParent").show();
						$(".addProgress").width(0);
						$(".addProgress").width(sha1*96);
					}
			});
		});
	});	
	
	/* -------------------------删除图片--------------------------- */
	$(function(){
		$("#deleteMainPic").on('click',function(e){
			$(".mainProgress").width(0);
			$("#mainPicShow").attr("src",$.getVirtualPath()+"/images/we/invitationIndex/bg1.jpg");
			$("#mainImg").val("");
		});
		
		$("#deleteAddPic").on('click',function(e){
			$(".addProgress").width(0);
			$("#addPicShow").attr("src",$.getVirtualPath()+"/images/we/invitationIndex/bg1.jpg");	
			$("#addImg").val("");
		});
	});
	
	/* -------------------------产品链接--------------------------- */
	/* $(function(){
		$("#insuranceLink").on('change',function(e){

		var link=$("#insuranceLink").val();
		var linkStart = link.indexOf("http://");
		if(linkStart == 0){
			   return true;
			}else{
				$("#insuranceLink").val("http://"+link);
			}
		})
	}) */
	/* -------------------------显示已选中人群--------------------------- */
	$(function(){
		$("#peopleId option").remove();
		var insurancePeopleIds=$("#insurancePeopleIds").val();
		var insuranceId=$("#id").val();
		var url = $.getVirtualPath()+ "/admin/insu/insurance/queryInsurancePeopleId";
		var insurancePeoples = $.getJsonPost(url);
		
		if($.isNull(insurancePeoples)){
			return;
		}
		var options=[];
		
		$.each(insurancePeoples,function(index,insurancePeople){
			var selected="";
			if(!$.isNull(insurancePeopleIds)){
				selected=insurancePeopleIds.indexOf(insurancePeople.id)>=0?"selected=selected":"";	
			}
			
			options.push("<option "+selected+" value='"+insurancePeople.id+"'>"+insurancePeople.name+"</option>");
		});
		
		$("#peopleId").append(options);
  
	})
	 
	
	//动态显示一级分享奖和推广奖比例
	   $("#totalProportion").on('change',function(){
		 var total=$("#totalProportion").val();
		 var action = $.getVirtualPath()+ "/admin/insu/insurance/proportion";
		
		 $.ajax({
				url:action,
				type:'post',
				dataType:'json',
				data:{total:total},
				success:function(insurance){
				
				$("#shareProportionOne").val(insurance.shareProportionOne);
				$("#spreadProportion").val(insurance.spreadProportion);
				}
		 });
	 })  
	 
	$(function(){
		 var minPremium=$("#minPremium").val();
		 var totalProportion=$("#totalProportion").val();
		if(minPremium <= 0.0){
			$("#minPremium").val("");
		};
		if(totalProportion <= 0.0){
			$("#totalProportion").val("");
		}
		 
	 }) 
	 
	  $(function(){
		 var insuSortCode=$("#insuSortCode").val();
		 if(insuSortCode == 0){
			 $("#insuSortCode").val("");
		 }
	 }); 
	 
	 $("#insuSortCode").on("click",function(){
		 var insuranceOne=$("#insuranceOne").val();
		 
		 if(insuranceOne == "财产险"){
			 $("#insuSortCode").attr("placeholder","请输入1-1000的数");
		 }else if(insuranceOne == "理财险"){
			 $("#insuSortCode").attr("placeholder","请输入1001-2000的数")
		 }else if(insuranceOne == "健康险"){
			 $("#insuSortCode").attr("placeholder","请输入2001-3000的数")
		 }else if(insuranceOne == "意外险"){
			 $("#insuSortCode").attr("placeholder","请输入3001-4000的数")
		 }
	 })
	 
	 $(function(){
		 var status=$("#status").val();
		 if(status=="newInsurance"){
			 $("#hotInsu").hide();
			$("#hotSortCode").hide();
			$("#hotSortCode").val(0);
		 }
	 })
		
		$("#status").on("change",function(){
			var status=$("#status").val();
		if(status=="hotInsurance"){
			$("#hotSortCode").val("");
			$("#hotInsu").show();
			$("#hotSortCode").show();
		}else if(status=="newInsurance"){
			$("#hotInsu").hide();
			$("#hotSortCode").hide();
		}
		});

</script>
<%@ include file="/WEB-INF/views/shared/base/scripts/jqueryui.jsp"%>
<%@ include file="/WEB-INF/views/shared/base/scripts/limitless/default/formselects.jsp"%>
<%@ include file="/WEB-INF/views/shared/base/scripts/limitless/default/formstyling.jsp"%>
<%@ include file="/WEB-INF/views/shared/base/scripts/limitless/default/formpickers.jsp"%>
<%@ include file="/WEB-INF/views/shared/master/dialog.jsp"%>
<%@ include file="/WEB-INF/views/shared/scripts/editor/ueditor.jsp"%>
<%@ include file="/WEB-INF/views/shared/base/scripts/tools/upload-cos.jsp"%>
<%@ include file="/WEB-INF/views/shared/master/contentFooter.jsp"%>
